package com.xc.h05.controller.wyl;

import com.xc.h05.entity.Systemuser;
import com.xc.h05.service.wyl.SystemuserService;
import com.xc.h05.util.R;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system")
@CrossOrigin
public class SystemuserController {
    @Autowired
    private SystemuserService ststemuserService;
    @GetMapping("/findAll")
    public R findAll(Integer pageNum, Integer pageSize){
        return R.ok(ststemuserService.findAll(pageNum,pageSize));
    }
   @PostMapping()
   public R insert(@RequestBody Systemuser systemuser){
       int i = ststemuserService.insert(systemuser);
       if(i>0){
           return R.ok("新增成功");
       }else{
           return R.fail("新增失败");
       }
    }
    @PutMapping()
    public R update(@RequestBody Systemuser systemuser){
        int i = ststemuserService.update(systemuser);
        if(i>0){
            return R.ok("修改成功");
        }else{
            return R.fail("修改失败");
        }
    }
    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Long id){
        int i = ststemuserService.delete(id);
        if(i>0){
            return R.ok("删除成功");
        }else{
            return R.fail("删除失败");
        }
    }
    @GetMapping("/{id}")
    public R findById(@PathVariable("id") Long id){
        return R.ok(ststemuserService.findById(id));
    }
}
